package config

import (
	"flag"
	"github.com/BurntSushi/toml"
	"github.com/sirupsen/logrus"
)

var Config Conf

type Conf struct {
	Level    string
	Http     Http
	Influxdb Influxdb
}

type Http struct {
	Port int
	Host string
}

type Influxdb struct {
	Port   int
	Host   string
	Org    string
	Bucket string
	Token  string
}

func init() {
	var (
		log        string
		configPath string
	)
	flag.StringVar(&log, "log", "debug", "日志级别")
	flag.StringVar(&configPath, "config", "./server.toml", "配置文件")
	flag.Parse()
	_, err := toml.DecodeFile(configPath, &Config)
	if err != nil {
		logrus.Errorf("配置文件解析失败：%v", err)
	}
	logrus.Printf("当前配置信息：%+v", Config)
}
